<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Area extends Model
{
    
    protected $table = 'area';

    protected $primaryKey = 'area_id';

    public $timestamps = false;

    protected $appends = ['status_format', 'operation', 'checkbox', 'show_child', 'sort_format'];

    public function getStatusFormatAttribute()
    {
        $result = $this->area_status ? '展示' : '隐藏';
        return $result;
    }

    public function getSortFormatAttribute()
    {
        $result = "<span onclick=layInput(0,'请输入排序号','/admin/area/sortsave','{$this->area_id}','{$this->area_sort}')>{$this->area_sort}</span>";
        return $result;
    }

    public function getShowChildAttribute()
    {
        $result = '<a href="/admin/area/datalist/'.$this->area_id.'">查看</a>';
        return $result;
    }

    public function getCheckboxAttribute()
    {
        $html = '<label><input type="checkbox" name="checkboxList" value="'.$this->area_id.'" class="input-checkbox"><i>✓</i></label>';
        return $html;
    }

    public function getOperationAttribute()
    {
        $html  = "<i class='fa fa-edit' onclick=layOpenView('/admin/area/editview/{$this->area_id}','80%','80%','地区编辑')></i>";
        if ($this->area_status) {
            $html .= "<i class='fa fa-level-down ml-15' onclick=layChangeStatus('/admin/area/status/{$this->area_id}/0','隐藏')></i>";
        } else {
            $html .= "<i class='fa fa-level-up ml-15' onclick=layChangeStatus('/admin/area/status/{$this->area_id}/1','展示')></i>";
        }
        $html .= "<i class='fa fa-trash-o ml-15' onclick=layListDel(this,'/admin/area/destroy','{$this->area_id}','tr')></i>";
        return $html;
    }
}
